package com.meetup.caug.gitrdone;

import java.util.List;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.meetup.caug.gitrdone.model.Task;

public class AddTask extends Activity {

    MainApplication ma;

    List<Task> taskList;

    EditText taskTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_task);

        ma = (MainApplication) getApplication();
        taskList = ma.getTasks();
        Button addTask = (Button) findViewById(R.id.addTaskBTN);
        taskTitle = (EditText) findViewById(R.id.newTaskTitle);

        addTask.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                String taskName = taskTitle.getText().toString();
                Task task = new Task(taskName);
                taskList.add(task);
                int taskNumber = taskList.size();

                Log.v("ez", "taskList size " + taskList.size());

                SharedPreferences sp = PreferenceManager
                        .getDefaultSharedPreferences(getApplicationContext());
                sp.edit().putString("task" + taskNumber, taskName).commit();
                sp.edit().putInt("numTasks", taskNumber).commit();

                finish();
            }
        });
    }
}